/**
 * 
 */
package net.oov.identify.junit;

import static org.junit.Assert.fail;

import java.io.StringReader;

import junit.framework.Assert;
import net.oov.identify.Buck;
import net.oov.identify.OI;
import net.oov.identify.SequenceFreqContainer;
import net.oov.identify.SequenceFreqContainerFactory;

import org.apache.lucene.analysis.TokenStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.wltea.analyzer.lucene.IKAnalyzer;

/**
 * @author huangsui.cn
 *
 */
public class TestSequenceFreqContainerFactory {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link net.oov.identify.SequenceFreqContainerFactory#getDefaultContainer()}.
	 */
	@Test
	public final void testGetDefaultContainer() {
		
		StringReader sr = new StringReader("^凡诺品牌 水洗磨白直筒牛仔裤【凡诺】");
		IKAnalyzer ik = new IKAnalyzer();
		
		SequenceFreqContainerFactory cf = new SequenceFreqContainerFactory();
		SequenceFreqContainer sfc = new SequenceFreqContainer(SequenceFreqContainer.LOAD_METHOD_FORWARD,5);
		
		TokenStream ts = ik.tokenStream("product name", sr);
		cf.addRawCharSequence(sfc, ts);
		OI.wl(sfc.toString());
		
		Buck buck = new Buck(sfc.getDicForward());
		Assert.assertTrue(buck.freq("凡").intValue() == 2);
		Assert.assertTrue(buck.freq("诺").intValue() == 2);
		Assert.assertTrue(buck.freq("凡诺").intValue() == 2);
		Assert.assertTrue(buck.freqWhole("凡诺").intValue() == 1);
		Assert.assertTrue(buck.freq("直筒").intValue() == 1);
		Assert.assertTrue(buck.freqWhole("直筒").intValue() == 0);
		Assert.assertTrue(buck.findTreeNode("凡诺").getKey().equals('诺'));
		Assert.assertTrue(buck.findTreeNode("直筒").getKey().equals('筒'));
		
	}

	/**
	 * Test method for {@link net.oov.identify.SequenceFreqContainerFactory#getDefaultRevContainer()}.
	 */
	@Test
	public final void testGetDefaultRevContainer() {
		fail("Not yet implemented"); // TODO
	}

}
